﻿#ifndef __SECLSL_SN_MGR_H__
#define __SECLSL_SN_MGR_H__


#include"../DataBase/EvSecIslSNData.hpp"
#include"../Base/Concurrency/SpinLock.hpp"
#include<unordered_map>
#include<string>
#include<memory>
#include"rapidjson/document.h"


namespace SC_SUN
{

class MapApp;

class SecIslSNManGR
{

protected:

    ///环境服务对象
    MapApp& mApp;

    //保存数据
    rapidjson::Document mInfos;

    ///key值为SEC_ISL_SN，value为EvSatelliteData类型数据
    std::unordered_map<std::string, std::shared_ptr<EvSecIslSNData>> mSeclslSNs;

    ///key值为SEC_ISL_SAT1 + SEC_ISL_SAT2，value为EvSatelliteData类型数据
    std::unordered_map<std::string, std::shared_ptr<EvSecIslSNData>> mSatToSeclslSNs;

    ///这里获取星间信息是通过切片去找的，先把各切片的索引信息保存起来
    std::vector<rapidjson::GenericObject<false, rapidjson::Value>> mAllSliceInfos;

    ///互斥锁
    MMF::SpinLock mMutex;

public:

    SecIslSNManGR(MapApp& app):mApp(app) {}
    ~SecIslSNManGR() {}

    int LoadData();

    int LoadBySlice(uint32_t slice);

    ///添加星间数据
    bool Add(const std::string& SEC_ISL_SN, const std::shared_ptr<EvSecIslSNData>& sat);

    ///查找星间数据
    bool Find(const std::string& SEC_ISL_SN);

    ///获取星间数据
    EvSecIslSNData* Get(const std::string& SEC_ISL_SN);

    ///通过两颗卫星获取星间星系
    EvSecIslSNData* GetBySatellite(const std::string& SEC_ISL_SAT1, const std::string& SEC_ISL_SAT2);

    ///删除星间数据
    bool Delete(const std::string& SEC_ISL_SN);

    ///更新星间数据
    bool Update(const std::string& SEC_ISL_SN, const std::shared_ptr<EvSecIslSNData>& sat);

    //获取仿真时长
    void GetTimeAndStep(double& time, double& step);

};

}

#endif